#define _GNU_SOURCE
#include "app_runner.h"
#include "app_pool.h"
#include "app_serial.h"
#include "log/log.h"
#include "app_router.h"
#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int stop_handler(int sig)
{
    if (sig == SIGINT || sig == SIGTERM)
    {
        return 0;
    }
}

int running = 1;

int app_runner_run(void)
{
    signal(SIGINT, stop_handler);
    signal(SIGTERM, stop_handler);
    if (app_pool_init(5) == 0)
    {
        log_error("app_pool_init failed");
        return -1;
    }

    app_router_init();
    SerialDevice *serial = app_serial_init("/dev/ttyS1");
    app_router_register_device(&serial->super);

    while (running)
    {

        usleep(1000 * 200);
    }
    app_router_close();
    app_pool_close();
    return 0;
}